﻿namespace NebulaServer.WcfServices
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.IO;
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;

    public class Administration : IAdministration
    {
        public bool Reboot(string user, string password, string pluginPath)
        {
            try
            {
                var aggregateCatalog = new AggregateCatalog();

                // get all sub-folder to find plugin dll
                var pluginsPath = Directory.GetDirectories(pluginPath, "*", SearchOption.TopDirectoryOnly).ToList();
                foreach (var path in pluginsPath)
                {
                    aggregateCatalog.Catalogs.Add(new DirectoryCatalog(path));
                }

                CompositionContainer container = new CompositionContainer(aggregateCatalog);

                // retrieve all imports/exports in plugins and nebula server
                // and compose them
                CompositionBatch batch = new CompositionBatch();
                batch.AddPart(container);
                container.Compose(batch);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Install(string user, string password, FileStream plugin)
        {
            throw new NotImplementedException();
        }

        public bool Remove(string user, string password, string plugin)
        {
            throw new NotImplementedException();
        }

        public bool Clean(string user, string password)
        {
            throw new NotImplementedException();
        }

        public bool Backup(string user, string password)
        {
            throw new NotImplementedException();
        }

        public bool Clone(string user, string password, string urlDestination)
        {
            throw new NotImplementedException();
        }
    }
}
